package org.linlinjava.litemall.app.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.databind.ser.Serializers;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.entity.Gamch;
import org.linlinjava.litemall.db.entity.Goods;
import org.linlinjava.litemall.db.service.IGamchService;
import org.linlinjava.litemall.db.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 主播商户 前端控制器
 * </p>
 *
 * @author shuyi
 * @since 2019-11-14
 */
@RestController
@RequestMapping("/app/gamch")
public class GamchController extends BaseController {
    public void setMchId(Integer mchId) {
        this.mchId = mchId;
    }

    private Integer mchId;
    private Gamch mch;

    public void setMch(Gamch mch) {
        this.mch = mch;
    }

    @Autowired
    private IGamchService gamchService;
    @Autowired
    private IGoodsService goodsService;

    @PostMapping("apply")
    public Object apply(@RequestBody Gamch gamch){
        int uid=this.getUid();

        if(!gamchService.canApply(uid)){
            return ResponseUtil.fail(-1,"申请正在审核中或已通过,请勿重复申请!");
        }

        gamch.setUid(this.getUid());
        gamch.setIstatus(2);
        gamchService.save(gamch);

        return ResponseUtil.ok(gamch);
    }

    @PostMapping("find_by_uid")
    public Object findByUid(@RequestBody Gamch gamch){

//        return ResponseUtil.ok(gamchService.findByUid(this.getUid()));
        return ResponseUtil.ok(this.mch);
    }



    @PostMapping("add_goods")
    public Object addGoods(@RequestBody Goods goods){
        goods.setMchId(this.mchId);
        goodsService.save(goods);
        return ResponseUtil.ok();
    }

    @PostMapping("update_goods")
    public Object updateGoods(){


        return ResponseUtil.ok();
    }
}
